//
//  CustomViewManager.m
//  RNOCMutuallyDemo
//
//  Created by Harvey on 2017/7/17.
//  Copyright © 2017年 Facebook. All rights reserved.
//

#import "CustomViewManager.h"
#import "CustomView.h"
@interface LocalCustomView () <UIAlertViewDelegate>
  
@property (nonatomic, copy) RCTResponseSenderBlock callBack;
@end

@implementation LocalCustomView
  
RCT_EXPORT_MODULE()
- (dispatch_queue_t)methodQueue
{
  return dispatch_get_main_queue();
}

RCT_EXPORT_VIEW_PROPERTY(titleString, NSString);
RCT_EXPORT_VIEW_PROPERTY(contentString, NSString);

- (UIView *)view {
  return [[CustomView alloc] init];
  
}

RCT_EXPORT_METHOD(alertChooseWithCallBack:(RCTResponseSenderBlock)callBack)
{
  self.callBack = callBack;
  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"调用了原生Alert" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
  alert.delegate = self;
  [alert show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  if (buttonIndex == 0) {
    if (self.callBack) self.callBack(@[@"点击了”取消“"]);
  } else {
    if (self.callBack) self.callBack(@[@"点击了“确定”"]);
  }
}
@end
